﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EyFramework.Common;
using HzybService;
using HzybService.BaseInData;
using HzybService.BaseOutData;
using YbService.Core.Service;
using YbService.Entity.Dto;
using YbService.Entity.Hzyb;

namespace InsuService
{
    public class YbService
    {
        public static object GetInsuAccount(InsuAccountParam card)
        {
            if (!string.IsNullOrEmpty(card.CanBaoDiXzqhdm))
            {
                //根据读卡的信息，换取医保的信息
                if (card.CanBaoDiXzqhdm.StartsWith("3301"))
                {
                    #region 换取杭州医保的账户信息

                    return GetHzybAccount(card);

                    #endregion 换取杭州医保的账户信息
                }
                else
                {
                    #region 换取全国一卡通的账户信息

                    //return GetQgyktAccount(card);
                    throw new BizException("全国一卡通医保电子凭证还不支持！");

                    #endregion 换取全国一卡通的账户信息
                }
            }
            return null;
        }

        /// <summary>
        /// 获取医保账户
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        private static object GetHzybAccount(InsuAccountParam card)
        {
            RcHuoQuRyjbxx huoQuRyjbxx = new RcHuoQuRyjbxx();
            huoQuRyjbxx.KaLeiXing = "7|" + card.DianZiPzxx.DzpzStr;
            huoQuRyjbxx.CanBaoDtcq = card.CanBaoDiXzqhdm;
            huoQuRyjbxx.JiaoYiLx = "2100";
            huoQuRyjbxx.JiaoYiLxmc = "获取人员基本信息";
            huoQuRyjbxx.KaHao = card.ShenFenZh;
            huoQuRyjbxx.ChaXunSj = PublicService.GetSysDate("YYYYMMDDHH24MISS");
            HzybAccount account = HZSiInterface.HuoQuRyjbxx2100(huoQuRyjbxx);
            account.KaLeiXing = huoQuRyjbxx.KaLeiXing;
            return account;
        }

        /// <summary>
        /// 建立就诊档案
        /// </summary>
        /// <param name="jianLiJzda"></param>
        /// <returns></returns>
        public static object JianLiJzda(RcJianLiJzda jianLiJzda, HzybAccount account)
        {
            jianLiJzda.CanBaoDtcq = account.CanBaoDxzqhdm;
            jianLiJzda.KaLeiXing = account.KaLeiXing;
            jianLiJzda.JiaoYiLx = "2210";
            jianLiJzda.JiaoYiLxmc = "建立就诊档案";
            JianLiJzda jzda = HZSiInterface.JianLiJzda2210(jianLiJzda);
            return jzda;
        }

        /// <summary>
        /// 处方明细上传
        /// </summary>
        /// <param name="chuFangMxsc"></param>
        /// <param name="account"></param>
        /// <returns></returns>
        public static object ChuFangMxsc(RcChuFangMxsc chuFangMxsc, HzybAccount account)
        {
            chuFangMxsc.KaLeiXing = account.KaLeiXing;
            chuFangMxsc.CanBaoDtcq = account.CanBaoDxzqhdm;
            chuFangMxsc.JiaoYiLx = "2310";
            chuFangMxsc.JiaoYiLxmc = "处方明细上传";
            ChuFangMxsc chuFangMxscOut = HZSiInterface.ChuFangMxsc2310(chuFangMxsc);
            return chuFangMxscOut;
        }

        /// <summary>
        /// 门诊收费预结算
        /// </summary>
        /// <param name="feiYong"></param>
        /// <param name="account"></param>
        /// <returns></returns>
        public static object MenZhenYjs(RcFeiYong feiYong, HzybAccount account)
        {
            feiYong.KaLeiXing = account.KaLeiXing;
            feiYong.CanBaoDtcq = account.CanBaoDxzqhdm;
            feiYong.JiaoYiLx = "2420";
            feiYong.JiaoYiLxmc = "门诊收费预结算";
            FeiYongJs feiYongYjs = HZSiInterface.FeiYongYjs2420(feiYong);
            return feiYongYjs;
        }

        /// <summary>
        /// 门诊收费结算
        /// </summary>
        /// <param name="feiYong"></param>
        /// <param name="account"></param>
        /// <returns></returns>
        public static object MenZhenJs(RcFeiYong feiYong, HzybAccount account)
        {
            feiYong.KaLeiXing = account.KaLeiXing;
            feiYong.CanBaoDtcq = account.CanBaoDxzqhdm;
            feiYong.JiaoYiLx = "2410";
            feiYong.JiaoYiLxmc = "门诊收费结算";
            FeiYongJs feiYongJs = HZSiInterface.FeiYongJs2410(feiYong);

            return feiYongJs;
        }
    }
}